import fetch from 'common/src/utils/fetch'
import UTILS from "common/src/utils/utils";
/**
 * 讲座分页列表
 */
export function lecturePage(data) {
    return fetch({
      url: '/api/cultureservice/lectureInformation/page',
      method: 'POST',
      data
    })
}
/**
 * 讲座详情
 */
export function lectureDetail(data) {
    return fetch({
      url: '/api/cultureservice/lectureInformation/getByStudentId?studentId='+data.studentId+'&pageNum_='+data.pageNum_+'&pageSize_='+data.pageSize_,
      method: 'GET'
    })
}

/**
 * 讲座列表导出
 */
export function lectureExport(data) {
    return fetch({
      url: '/api/cultureservice/lectureInformation/exportLectureInfo',
      method: 'POST',
      data
    })
}
export function downloadLecture(path){
    return fetch({
        url: '/api/cultureservice/lectureInformation/newDownload?path='+path,
        method: 'get',
        responseType: 'blob'
    }).then(res => {
        UTILS.downloadFile(res, '讲座信息.xls', 'application/vnd.ms-excel;charset=utf-8');
    });
}

export function exportLectureReport(data){
    return fetch({
        url: '/api/cultureservice/lectureInformation/exportLectureReport',
        method: 'POST',
        data
    })
}
function downloadFile(data, url, fileName) {
    fetch({
      url: url,
      method: 'POST',
      data,
      responseType: 'blob'
    }).then(resp => {
      if (!resp) {
        return;
      }
      let url = window.URL.createObjectURL(new Blob([resp]));
      let link = document.createElement('a');
      link.style.display = 'none';
      link.href = url;
      link.setAttribute('download', fileName);
      document.body.appendChild(link);
      link.click();
    });
  }
export default {
    lecturePage:lecturePage,
    lectureDetail:lectureDetail,
    lectureExport:lectureExport,
    downloadLecture:downloadLecture,
    exportLectureReport:exportLectureReport
}